<!DOCTYPE html>
<html>
<head>
    <title></title>
    @if(isset($_GET['MT'])) @@include('system::admin.Layouts.index-layui-head') @else @include('system::admin.Layouts.index-layui-head') @endif
    <link rel="stylesheet" href="/Modules/system/sys/css/index.css" media="all">
    @section('self_extend_css')
    @show
</head>
<body>

<div class="layuimini-container">

    @section('self_extend_div')
    @show

    <div class="layuimini-main">
        {{--这些是搜索项--}}
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                         @section('Search_terms')
                            @foreach ($formSearch as $ks => $one)
                                @switch($one->search_type)
                                    @case(1)
                                    {{--文本框like搜索--}}
                                    <div class="layui-inline">
                                        <label class="layui-form-label">{{$one->name}}</label>
                                        <div class="layui-input-inline">
                                            <input type="text" data-search-type="like" name="{{$one->field}}" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    @break
                                    @case(2)
                                    {{--写死下拉选项下拉搜索--}}
                                    <div class="layui-inline">
                                        <label class="layui-form-label">{{$one->name}}</label>
                                        <div class="layui-input-inline">
                                            <select data-search-type="=" name="{{$one->field}}" lay-verify="required">
                                                <option value="-1">全部</option>
                                                @if(isset($_GET['MT'])) @@foreach ($formSearch[{{$ks}}]->search_extend['search'] as $key=>$search_extend) <option value="@{{$key}}">@{{$search_extend}}</option> @@endforeach
                                                @else
                                                    @foreach ($one->search_extend['search'] as $key=>$search_extend)
                                                        <option  value="{{$key}}">{{$search_extend}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    @break
                                    @case(3)
                                    {{--模型读表信息下拉搜索--}}
                                    <div class="layui-inline">
                                        <label class="layui-form-label">{{$one->name}}</label>
                                        <div class="layui-input-inline">
                                            <select data-search-type="=" name="{{$one->field}}" lay-verify="required">
                                                <option value="-1">全部</option>
                                                @if(isset($_GET['MT'])) @@foreach ($formSearch[{{$ks}}]->option3 as $key=>$search_extend) <option value="@{{$key}}">@{{$search_extend}}</option> @@endforeach
                                                @else
                                                    @foreach ($one->option3 as $key=>$search_extend)
                                                        <option value="{{$key}}">{{$search_extend}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    @break
                                    @case(4)
                                    {{--时间区间搜索--}}
                                    {{$one->name}}:
                                    <div class="layui-inline">
                                        <label class="layui-form-label">开始</label>
                                        <div class="layui-input-inline">
                                            <input id="{{$one->field}}" type="text" data-search-type=">=" name="{{$one->field}}" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <span style="margin-right:15px;">到</span>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">结束</label>
                                        <div class="layui-input-inline">
                                            <input id="{{$one->field}}_end" type="text" data-search-type="<=" name="{{$one->field}}" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    @break
                                    @default
                                @endswitch
                            @endforeach

                        @show

                        @section('self_extend_search')
                        @show

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>

                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">

                @section('self_extend_operation')
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
                @show

            </div>
        </script>

        {{--表格主体--}}
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        {{--列表操作--}}
        <script type="text/html" id="currentTableBar">
            @section('self_currentTableBar')
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            @show
        </script>

    </div>

</div>

@if(isset($_GET['MT']))
    @@include('system::admin.Layouts.index-layui-top')
@else
    @include('system::admin.Layouts.index-layui-top')
@endif

@section('self_extend_js')
@show

<script>

    layui.use(['form', 'table','laydate','arrayJs','chinAdmin','allJs'], function () {

        var $ = layui.jquery, form = layui.form, table = layui.table,laydate = layui.laydate,chinAdmin = layui.chinAdmin,allJs = layui.allJs;

        //头部搜索初始化组件
        @foreach ($form as $one)
            @switch($one->search_type)
                @case(4)
                    //时间区间选择
                    laydate.render({
                        elem: '#{{$one->field}}',
                        type:'datetime',
                    });
                    laydate.render({
                        elem: '#{{$one->field}}_end',
                        type:'datetime',
                    });
                @break
            @default
            @endswitch
        @endforeach

        //所有的项配置
        var $cols = [
            {type: "checkbox", width: 50},
            //逐步放弃这种扩展方式，采用头部<script type="text/html" id="currentTableBar">块扩展
            {title: '操作', minWidth: 190, toolbar: '#currentTableBar', align: "center"},

            @foreach ($form as $key => $one)
            {field: '{{$one->field}}', width: '{{$one->width}}', title: '{{$one->name}}',sort: parseInt('{{$one->is_sort}}'),templet: function(d){
                @switch($one->type)
                @case(4)
                //范围
                var range = JSON.parse(d.{{$one->field}});
                return "开始:"+range.begin+"-结束:"+range.end;
                @break
                @case(5)
                //下拉
                @if(isset($_GET['MT']))
                    var {{$one->field}}_extends_5 = JSON.parse('@{!! (gettype($form[{{$key}}]->extends) == 'array')?json_encode($form[{{$key}}]->extends):($form[{{$key}}]->extends?$form[{{$key}}]->extends:"{}") !!}');
                @else
                    var {{$one->field}}_extends_5 = JSON.parse('{!! (gettype($one->extends) == 'array')?json_encode($one->extends):($one->extends?$one->extends:"{}") !!}');
                @endif

                for(var i in {{$one->field}}_extends_5){
                    if(i == d.{{$one->field}}){
                        return '<button type="button" class="layui-btn layui-btn-xs">'+{{$one->field}}_extends_5[i]+'</button>';
                    }
                }
                @break
                @case(9)
                if(d.{{$one->field}} == '' || d.{{$one->field}} == null){
                    return "";
                }else{
                    //如果存的是个对象字符串就解析
                    if(d.{{$one->field}}.indexOf("{") != -1 ){
                        //复选框
                        var range = JSON.parse(d.{{$one->field}});
                        var str = '';
                        for(var i in range){
                            str+=range[i]+" ";
                        }
                        return str;
                    }else{
                        return d.{{$one->field}};
                    }
                }
                @break
                @case(10)
                if(d.{{$one->field}} == '' || d.{{$one->field}} == null){
                    return "";
                }else{
                    //如果存的是个对象字符串就解析
                    if(d.{{$one->field}}.indexOf("{") != -1 ){
                        //原始复选框
                        var range = JSON.parse(d.{{$one->field}});
                        var str = '';
                        for(var i in range){
                            str+=range[i]+" ";
                        }
                        return str;
                    }else{
                        return d.{{$one->field}};
                    }
                }
                @break
                @case(11)
                //活动开关
                @if(isset($_GET['MT']))
                var {{$one->field}}_extends = JSON.parse('@{!! $form[{{$key}}]->extends !!}');
                @else
                var {{$one->field}}_extends = JSON.parse('{!! $one->extends !!}');
                @endif

                return (d.{{$one->field}} == "on")?'<button type="button" class="layui-btn layui-btn-xs">'+{{$one->field}}_extends.name.on+'</button>':'<button type="button" class="layui-btn layui-btn-xs layui-btn-normal">'+{{$one->field}}_extends.name.off+'</button>';
                @break
                @case(12)
                //开关
                return (d.{{$one->field}} == 'on')?"开":"关闭";
                @break
                @case(13)
                //活动开关
                @if(isset($_GET['MT']))
                    var {{$one->field}}_extends_13 = JSON.parse('@{!! $form[{{$key}}]->extends !!}');
                @else
                    var {{$one->field}}_extends_13 = JSON.parse('{!! $one->extends !!}');
                @endif
                //寻找扩展信息里面对应的汉字显示值。
                for(var i in {{$one->field}}_extends_13){
                    if(i == d.{{$one->field}}){
                        return '<button type="button" class="layui-btn layui-btn-xs">'+{{$one->field}}_extends_13[i].title+'</button>';
                    }
                };
                return "";
                @break
                @case(17)
                //图片
                var src = d.{{$one->field}};
                if(src == null){
                    return "";
                }

                src = src.replace('[', '').replace(']', '');

                var src_arr = src.split(",");

                if(src == null){
                    return "无";
                }else{
                    return "<img class='show_this' src="+src_arr[0]+" width='30'>";
                }
                @break
                @case(18)
                //选择##防止没有报错
                if(typeof(d.{{$one->extends_array['relation']}}) == "undefined" || d.{{$one->extends_array['relation']}} == null){
                    return "";
                }else{
                    return d.{{$one->extends_array['relation']}}.{{$one->extends_array['showName']}};
                }
                @break
                @default
                    return d.{{$one->field}}?d.{{$one->field}}:'';
                @endswitch
                }},
            @endforeach

        ];

        //son子模板$cols扩展编辑项
        typeof self_extend_cols === "function" ? ($cols = self_extend_cols($cols,layui)) : false;

        //通用调用
        layui.$cols = $cols,layui.$ThisGet = '{{$ThisGet}}',layui.$class = '{{$class}}',layui.$this_id = '{{$id}}',layui.$table = '{{$table}}',layui.$Modules = '{{$Modules}}';
        chinAdmin.index(layui);

    });
</script>

</body>
</html>